package com.doyens.gmall.cart.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.doyens.gmall.cart.mapper.CartInfoMapper;
import com.doyens.gmall.model.cart.CartInfo;
import com.doyens.gmall.cart.service.CartAsyncService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
 * Classname:CartAsyncService
 * PackageName:com.doyens.gmall.service.impl
 *
 * @Author:uyijk
 * @Create:2023/8/9 15:38
 * @Version: 1.0
 */
@Service
public class CartAsyncServiceImpl implements CartAsyncService {
    @Autowired
    private CartInfoMapper cartInfoMapper;
    @Override
    @Async
    public void addToCart(CartInfo cartInfo) {
        //添加到数据库
        cartInfoMapper.insert(cartInfo);
    }

    @Override
    @Async
    public void updateCartInfo(CartInfo cartInfo) {
        cartInfoMapper.updateById(cartInfo);
    }

    @Override
    @Async
    public void deleteByUserId(String userId) {
        LambdaQueryWrapper<CartInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CartInfo::getUserId,userId);
        cartInfoMapper.delete(queryWrapper);
    }

    @Override
    @Async
    public void deleteByUserIdAndSkuId(String userId,Long skuId) {
        LambdaQueryWrapper<CartInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CartInfo::getUserId,userId);
        queryWrapper.eq(CartInfo::getSkuId,skuId);
        cartInfoMapper.delete(queryWrapper);
    }

}
